
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>计时</title>
		<script type="text/javascript">
			function showLeftTime(){
				var now=new Date();
				var year=now.getFullYear();
				var month=now.getMonth()+1;
				if(month<10){
					month='0'+month;
				}
				var day=now.getDate();
				if(day<10){
					day='0'+day;
				}
				var hours=now.getHours();
				if(hours<10){
					hours='0'+hours;
				}
				var minutes=now.getMinutes();
				if(minutes<10){
					minutes='0'+minutes;
				}
				var seconds=now.getSeconds();
				if(seconds<10){
					seconds='0'+seconds;
				}
				var showTime=year+"年"+month+"月"+day+"日 "+hours+":"+minutes+":"+seconds+"";
				//一秒刷新一次显示时间
				var timeID=setTimeout(showLeftTime,1000);
				document.getElementById("showtime").innerHTML=showTime;
			}
			
			function mydate(){
				var today = Date.now();
				var myday = new Date(document.getElementById("mydate").value).getTime();
				//返回累计毫秒数(从1970/1/1午夜)
				var showleft = parseInt((myday - today)/1000);
				var timeID=setTimeout(mydate,1000);
				document.getElementById("showlefttime").innerHTML=showleft;
			}
		</script>
    </head>
    <body>
		<span id="showtime"></span><br/>
		<button onclick="showLeftTime()">现在时间</button><br/>
		<input type="datetime-local" id="mydate"/><br/>
		<span id="showlefttime"></span><br/>
		<button onclick="mydate()">倒计时</button><br/>
	</body>
</html>